package com.example.mapper;

import com.example.entity.Work;
import com.example.entity.Teacher;
import com.example.entity.Work;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface WorkMapper {
    void insert(Work work);


    @Select("select work.*, teacher.name as teacherName, student.name as studentName from work " +
            "left join teacher on work.teacher_id = teacher.id " +
            "left join student on work.student_id = student.id ")
    List<Work> selectAll();

    @Select("select work.*, student.name as studentName,teacher.name as teacherName from work" +
            "left join teacher on work.teacher_id=teacher.id " +
            "left join studernt on work.student_id=student.id " +
            "where work.name like  concat('%',#{name},'%')")
    List<Work> selectByName(String name);

    void updateById(Work work);

    @Delete("delete from work where id=#{id}")
    void deleteById(Integer id);

    //依据教师id搜索相关课程
    @Select("select work.*, teacher.name as teacherName, student.name as studentName from work " +
            " left join student on work.student_id=student.id " +
            " left join teacher on work.teacher_id=teacher.id " +
            "where student.name like  concat('%',#{name},'%') and teacher.id=#{teacherId}")
    List<Work> selectByNameAndTeacherId(@Param("name") String name, @Param("teacherId") Integer teacherId);


    @Select("select work.*, teacher.name as teacherName, student.name as studentName from work " +
            "left join teacher on work.teacher_id = teacher.id " +
            "left join student on work.student_id = student.id " +
            "where teacher.id = #{teacherId}")
    List<Work> selectAllByTeacherId(Integer teacherId);
    //依据学生id搜索相关课程
    @Select("select work.*, teacher.name as teacherName, student.name as studentName from work " +
            "left join student on work.student_id=student.id " +
            "left join teacher on work.teacher_id=teacher.id " +
            "where student.name like  concat('%',#{name},'%') and student.id=#{studentId}")
    List<Work> selectByNameAndStudentId(@Param("name") String name, @Param("studentId") Integer studentId);

    @Select("select work.*, teacher.name as teacherName, student.name as studentName from work " +
            "left join teacher on work.teacher_id = teacher.id " +
            "left join student on work.student_id = student.id " +
            "where student.id = #{studentId}")
    List<Work> selectAllByStudentId(Integer studentId);
}

